package com.eloisa.gls.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.eloisa.gls.domain.Test;
import com.eloisa.gls.service.ITestService;

@Controller
@RequestMapping("/test")
public class TestController {
	@Autowired
	private ITestService service;
	
	@RequestMapping(value="get" ,method=RequestMethod.GET)
	public String get(@RequestParam Integer id){
		Test test = service.getTest(id);
		System.out.println(test.getContent());
		return "index";
	}
	
	@RequestMapping(value="delete" ,method=RequestMethod.GET)
	public String delete(@RequestParam Integer id){
		service.deleteTest(id);
		return "index";
	}
	
	@RequestMapping(value="create" ,method=RequestMethod.GET)
	public String create(@RequestParam Integer id,@RequestParam Integer myKey,@RequestParam String content){
		Test test = new Test();
		test.setContent(content);
		test.setMyKey(myKey);
		test.setId(id);
		service.createTest(test);
		System.out.println(test.getContent());
		return "index";
	}
	
	@RequestMapping(value="update" ,method=RequestMethod.GET)
	public String update(@RequestParam Integer id,@RequestParam Integer myKey,@RequestParam String content){
		Test test = new Test();
		test.setContent(content);
		test.setMyKey(myKey);
		test.setId(id);
		service.updateTest(test);
		return "index";
	}
	
}
